import {
    upload
} from "@/request/api";
export function initEditor(editor, {
    height,
    placeholder,
    onchangeTimeout,
    pasteFilterStyle,
    uploadImgServer,
}) {
    editor.config.excludeMenus = [
        'emoticon',
        'video',
        'todo',
        'code',
    ]
    // 设置编辑区域高度为 400px
    editor.config.height = height || 500;
    editor.config.placeholder = placeholder || "在这里开始编辑你的论文吧！";
    // 配置触发 onchange 的时间频率，默认为 200ms
    editor.config.onchangeTimeout = onchangeTimeout || 500; // 修改为 500ms
    //显示粘贴进来的文本样式
    editor.config.pasteFilterStyle = pasteFilterStyle || false;
    editor.config.uploadImgServer = uploadImgServer || "/api/upload";
    setTimeout(() => {
        // editor.txt.html(
        //     `<p>用 JS 设置的内容，首先第一个措误是css</p><div>接着第二 个措误，哦不是第二个措误是html</div><div>最后第三，个措误额，第三个措误是js</div>`
        // ); // 重新设置编辑器内容
        // editor.txt.append(
        //     '<table border="0" width="100%" cellpadding="0" cellspacing="0"><tbody><tr><th>编号</th><th>姓名</th><th>职称</th></tr><tr><td>1</td><td>张三</td><td>初级</td></tr><tr><td>2</td><td>李四</td><td>中级</td></tr><tr><td>3</td><td>王五</td><td><font color="#c24f4a">高级</font></td></tr></tbody></table>'
        // );
        editor.txt.html(`<div>
        <div style="text-align:center">
            <table cellspacing="0" cellpadding="0"
                style="width:456.75pt; margin-right:auto; margin-left:auto; border-collapse:collapse">
                <tr style="height:29.25pt">
                    <td style="width:47.05pt; padding:0.25pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:FangSong">分类号</span></p>
                    </td>
                    <td colspan="2"
                        style="width:57.45pt; border-bottom-style:dashed; border-bottom-width:0.75pt; padding:0.25pt 5.65pt 0.03pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:Calibri; font-weight:bold">&#xa0;</span></p>
                    </td>
                    <td colspan="3" style="width:204.35pt; padding:0.25pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:Calibri">&#xa0;</span></p>
                    </td>
                    <td colspan="2" style="width:36.45pt; padding:0.25pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:FangSong">密 级</span></p>
                    </td>
                    <td
                        style="width:57.45pt; border-bottom-style:dashed; border-bottom-width:0.75pt; padding:0.25pt 5.65pt 0.03pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:Calibri">&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:29.25pt">
                    <td style="width:47.05pt; padding:0.25pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:FangSong">U D C</span></p>
                    </td>
                    <td colspan="2"
                        style="width:57.45pt; border-top-style:dashed; border-top-width:0.75pt; border-bottom-style:dashed; border-bottom-width:0.75pt; padding:0.03pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:Calibri">&#xa0;</span></p>
                    </td>
                    <td colspan="3" style="width:204.35pt; padding:0.25pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:Calibri">&#xa0;</span></p>
                    </td>
                    <td colspan="2" style="width:36.45pt; padding:0.25pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:FangSong">编 号</span></p>
                    </td>
                    <td
                        style="width:57.45pt; border-top-style:dashed; border-top-width:0.75pt; border-bottom-style:dashed; border-bottom-width:0.75pt; padding:0.03pt 5.65pt; vertical-align:bottom">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:FangSong">XXX</span></p>
                    </td>
                </tr>
                <tr>
                    <td colspan="9" style="width:445.95pt; padding:0.25pt 5.65pt; vertical-align:top">
                        <p
                            style="margin-top:12pt; margin-bottom:10pt; text-align:center; line-height:115%; widows:0; orphans:0; font-size:22pt">
                            <img src="tempa41e0d425be94e51ab5b375a49f1fc0c.doc.001.jpeg" width="181" height="121" alt=""
                                style="-aw-left-pos:0pt; -aw-rel-hpos:column; -aw-rel-vpos:paragraph; -aw-top-pos:0pt; -aw-wrap-type:inline" />
                        </p>
                        <p
                            style="margin-top:12pt; margin-bottom:10pt; text-align:center; line-height:115%; widows:0; orphans:0; font-size:28pt">
                            <span style="font-family:SimSun; font-weight:bold">硕</span><span
                                style="font-family:SimSun; font-weight:bold">&#xa0;</span><span
                                style="font-family:SimSun; font-weight:bold"> 士</span><span
                                style="font-family:SimSun; font-weight:bold">&#xa0;</span><span
                                style="font-family:SimSun; font-weight:bold"> 学</span><span
                                style="font-family:SimSun; font-weight:bold">&#xa0;</span><span
                                style="font-family:SimSun; font-weight:bold"> 位</span><span
                                style="font-family:SimSun; font-weight:bold">&#xa0;</span><span
                                style="font-family:SimSun; font-weight:bold"> 论</span><span
                                style="font-family:SimSun; font-weight:bold">&#xa0;</span><span
                                style="font-family:SimSun; font-weight:bold"> 文</span></p>
                    </td>
                </tr>
                <tr style="height:63.85pt">
                    <td colspan="9" style="width:445.95pt; padding:0.25pt 5.65pt; vertical-align:top">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:center; line-height:115%; widows:0; orphans:0; font-size:22pt">
                            <span>&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:127.25pt">
                    <td colspan="9" style="width:445.95pt; padding:0.25pt 5.65pt; vertical-align:top">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:center; line-height:115%; widows:0; orphans:0; font-size:26pt">
                            <span style="font-family:楷体_GB2312; font-weight:bold">请输入</span><span
                                style="font-family:楷体_GB2312; font-weight:bold">论文标题</span></p>
                    </td>
                </tr>
                <tr style="height:31.5pt">
                    <td colspan="2" rowspan="5" style="width:51.25pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:26pt">
                            <span>&#xa0;</span></p>
                    </td>
                    <td colspan="2" style="width:140pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">研</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun"> 究</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun"> 生</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun"> 姓</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun"> 名：</span></p>
                    </td>
                    <td style="width:3.4pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-indent:98pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">：</span></p>
                    </td>
                    <td colspan="2" style="width:143.2pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="letter-spacing:1pt">&#xa0;</span></p>
                    </td>
                    <td colspan="2" rowspan="5" style="width:64.9pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:26pt">
                            <span>&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:31.5pt">
                    <td colspan="2" style="width:140pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">学</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun">号：</span></p>
                    </td>
                    <td style="width:3.4pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-indent:98pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">：</span></p>
                    </td>
                    <td colspan="2" style="width:143.2pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span>&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:31.5pt">
                    <td colspan="2" style="width:140pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">指导教师姓名</span><span style="font-family:SimSun">及</span><span
                                style="font-family:SimSun">职称：</span></p>
                    </td>
                    <td style="width:3.4pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-indent:98pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">：</span></p>
                    </td>
                    <td colspan="2" style="width:143.2pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span>&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:31.5pt">
                    <td colspan="2" style="width:140pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">专</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun"> 业</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun"> 名</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun"> </span><span
                                style="font-family:SimSun">称：</span></p>
                    </td>
                    <td style="width:3.4pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-indent:98pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">：</span></p>
                    </td>
                    <td colspan="2" style="width:143.2pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span>&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:31.5pt">
                    <td colspan="2" style="width:140pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">研</span><span style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun"> 究</span><span
                                style="font-family:SimSun">&#xa0;</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun"> 方</span><span
                                style="font-family:SimSun">&#xa0;</span><span style="font-family:SimSun"> </span><span
                                style="font-family:SimSun">向：</span></p>
                    </td>
                    <td style="width:3.4pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-indent:98pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span style="font-family:SimSun">：</span></p>
                    </td>
                    <td colspan="2" style="width:143.2pt; padding:0.25pt 5.65pt; vertical-align:middle">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:14pt">
                            <span>&#xa0;</span></p>
                    </td>
                </tr>
                <tr style="height:55.25pt">
                    <td colspan="9" style="width:445.95pt; padding:0.25pt 5.65pt; vertical-align:top">
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:16pt">
                            <span style="font-family:Calibri">&#xa0;</span></p>
                        <p
                            style="margin-top:0pt; margin-bottom:10pt; text-align:center; line-height:115%; widows:0; orphans:0; font-size:16pt">
                            <span style="font-family:SimHei">二〇</span><span style="font-family:SimHei">XX</span><span
                                style="font-family:SimHei">年 </span><span style="font-family:SimHei">月</span></p>
                    </td>
                </tr>
                <tr style="height:0pt">
                    <td style="width:69.65pt"></td>
                    <td style="width:25.1pt"></td>
                    <td style="width:97.8pt"></td>
                    <td style="width:3.8pt"></td>
                    <td style="width:26pt"></td>
                    <td style="width:102.85pt"></td>
                    <td style="width:50.75pt"></td>
                    <td style="width:0.75pt"></td>
                    <td style="width:80.05pt"></td>
                </tr>
            </table>
        </div>
        <p
            style="margin-top:0pt; margin-bottom:10pt; text-align:justify; line-height:115%; widows:0; orphans:0; font-size:10.5pt">
            <span>&#xa0;</span></p>
    </div>`)
        // console.log(editor.$textElem.elems[0]);
        // let html = editor.txt.html();
        // this.arr.map((r) => {
        //   console.log(r.f);
        //   html = html.replace(r.f, `<span style="color:red">${r.f}</span>`);
        // });
        // console.log(html);
        // editor.txt.html(html);
    }, 2000);
    editor.create();
}
export function uploadImg(editor) {
    editor.config.uploadImgMaxLength = 5;
    editor.config.uploadImgTimeout = 15 * 1000;
    editor.config.uploadImgHeaders = {
        Accept: "multipart/form-data",
    };
    editor.config.customUploadImg = (resultFiles, insertImgFn) => {
        // resultFiles 是 input 中选中的文件列表
        // insertImgFn 是获取图片 url 后，插入到编辑器的方法
        let forms = new FormData();
        for (var i = 0; i < resultFiles.length; i++) {
            forms.append("fileUrl", resultFiles[i]);
        }
        upload(forms).then((res) => {
            console.log(res);
            res.data.forEach((item) => {
                insertImgFn(item.url);
            });
        });
    };
}